import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

public class StudentManagement {
    private static List<String> students = new ArrayList<>(); // 存储学生的列表

    // 新增学生
    public void addStudent() {
        // 实现新增学生的逻辑
    }

    // 维护学生
    public void maintainStudent() {
        // 实现维护学生的逻辑
    }

    // 学生列表
    public void listStudents() {
        // 实现获取学生列表的逻辑
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(() -> {
            createAndShowGUI();
        });
    }

    private static void createAndShowGUI() {
        JFrame frame = new JFrame("学生管理");
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.setSize(400, 300);

        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(0, 1));
        frame.getContentPane().add(panel);

        JLabel label = new JLabel("学生管理功能", JLabel.CENTER);
        panel.add(label);

        JButton addStudentButton = new JButton("新增学生");
        addStudentButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String studentName = JOptionPane.showInputDialog(frame, "请输入学生姓名:");
                String className = JOptionPane.showInputDialog(frame, "请输入学生班级:");
                String groupName = JOptionPane.showInputDialog(frame, "请输入学生小组:");
                if (studentName != null && !studentName.trim().isEmpty() && className != null && !className.trim().isEmpty() && groupName != null && !groupName.trim().isEmpty()) {
                    students.add(studentName + " (班级: " + className + ", 小组: " + groupName + ")");
                    JOptionPane.showMessageDialog(frame, "学生添加成功: " + studentName);
                } else {
                    JOptionPane.showMessageDialog(frame, "学生姓名、班级和小组不能为空");
                }
            }
        });
        panel.add(addStudentButton);

        JButton maintainStudentButton = new JButton("维护学生");
        maintainStudentButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 实现维护学生的逻辑
                System.out.println("维护学生功能");
            }
        });
        panel.add(maintainStudentButton);

        JButton listStudentsButton = new JButton("学生列表");
        listStudentsButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                StringBuilder studentList = new StringBuilder();
                for (String s : students) {
                    studentList.append(s).append("\n");
                }
                JOptionPane.showMessageDialog(frame, studentList.length() > 0 ? studentList.toString() : "没有学生");
            }
        });
        panel.add(listStudentsButton);

        frame.setVisible(true);
    }
}
